package close.kenny.shell.model
{
	import close.kenny.common.remoting.IInvokeResponder;
	import close.kenny.shell.ShellFacade;
	import close.kenny.shell.model.services.UserService;
	import close.kenny.shell.model.vo.UserVO;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	import close.kenny.common.flexsession.FlexSession;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.interfaces.IProxy;
	import org.puremvc.as3.multicore.patterns.proxy.Proxy;

	public class LoginProxy extends Proxy implements IProxy
	{
		public static const NAME:String="LoginProxy";
		
		private var userService:UserService;
		public function LoginProxy()
		{
			super(NAME, data);
		}
		override public function onRegister():void
		{
		}
		override public function onRemove():void
		{
		}
		
		public function UserLogin(user:UserVO):void
		{
			userService=new UserService();
			var iInvokeResponder:IInvokeResponder=userService.login(user);
			iInvokeResponder.addResultListener(resultHandler);
			iInvokeResponder.addFaultListener(faultHandler);
		}
		private function resultHandler(event:ResultEvent):void
		{
			var b:Boolean=event.result;
			if(b==true){
				sendNotification(ShellFacade.LOGINSUCCESS);
			}
			else{
				sendNotification(ShellFacade.LOGINFAULT);
			}
				
		}
		private function faultHandler(event:FaultEvent):void
		{
			Alert.show(event.fault.toString());
		}
	}
}